//
//  MVCTableViewCell.m
//  TableViewDataSource
//
//  Created by hibo on 2019/6/10.
//  Copyright © 2019 hibo. All rights reserved.
//

#import "MVCTableViewCell.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
@implementation MVCTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _numLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-115, 0, 100, 50)];
        _numLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_numLabel];
        
        _addButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-120, 10, 30, 30)];
        [_addButton setTitle:@"-" forState:UIControlStateNormal];
        _addButton.backgroundColor = [UIColor grayColor];
        [self addSubview:_addButton];
        _desButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-40, 10, 30, 30)];
        [_desButton setTitle:@"+" forState:UIControlStateNormal];
        _desButton.backgroundColor = [UIColor grayColor];
        [self addSubview:_desButton];
        
        [_addButton addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];
        [_desButton addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}
-(void)btn:(UIButton *)button{
    if ([button.titleLabel.text isEqualToString:@"+"]) {
        _model.num = [NSString stringWithFormat:@"%d",[_model.num intValue]+1];
    }else{
        _model.num = [NSString stringWithFormat:@"%d",[_model.num intValue]-1];
    }
    self.numLabel.text = _model.num;
}
-(void)setModel:(Model *)model{
    _model = model;
    self.textLabel.text = model.name;
    self.numLabel.text = model.num;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
